// Created by Windward Studios - no copyright is claimed. This code can be used in
// any manner by anyone for any reason. There is no copyright of any kind on it. You may
// use it in commercial products. You may change it without sharing those changes.
// We ask that you keep the "created by Windward Studios" in a comment at the top.

namespace net.windward.utils.ado
{
	/// <summary>
	/// The root class for a table and view.
	/// </summary>
	public abstract class WrBaseTable : WrDbElement
	{
		private readonly bool isSystem;
		private readonly WrColumn[] columns;

		/// <summary>
		/// Create a table or view object.
		/// </summary>
		/// <param name="schema">The schema that owns this element. null if none, empty string if default and the default has no name.</param>
		/// <param name="name">The name of the table.</param>
		/// <param name="description">The description (metadata) of the table.</param>
		/// <param name="isSystem">True if a system table.</param>
		/// <param name="columns">The columns for this table/view.</param>
		protected WrBaseTable(string schema, string name, string description, bool isSystem, WrColumn[] columns)
			: base(schema, name, description)
		{
			this.isSystem = isSystem;
			this.columns = columns;
		}

		/// <summary>
		/// Copy constructor
		/// </summary>
		/// <param name="src">Source object.</param>
		protected WrBaseTable(WrBaseTable src) : base(src)
		{
			isSystem = src.isSystem;
			columns = new WrColumn[src.columns.Length];
			for (int ind=0; ind<columns.Length; ind++)
				columns[ind] = new WrColumn(src.columns[ind]);
		}

		/// <summary>
		/// True if this is a system table or view.
		/// </summary>
		public virtual bool IsSystem
		{
			get { return isSystem; }
		}

		/// <summary>
		/// Return all columns in a table or view.
		/// </summary>
		public WrColumn[] Columns
		{
			get { return columns; }
		}
	}
}
